package logic
/**
数据服务层
*/
import "github.com/gomodule/redigo/redis"

// 开启事务
func (p *Timer) startTrans(conn redis.Conn) error {
	return conn.Send("MULTI")
}

// 提交事务
func (p *Timer) commit(conn redis.Conn) ([]interface{}, error) {
	return redis.Values(conn.Do("EXEC"))
}

// 从zset中删除指定的任务ID
func (p *Timer) delJobPool(conn redis.Conn, jobIDs []string, topic string) error {
	args := make([]interface{}, len(jobIDs)+1)
	args[0] = KEY_JOB_POOL
	for k, v := range jobIDs {
		args[k+1] = v
	}
	return conn.Send("ZREM", args...)
}

// 插入ReadyQueue
func (p *Timer) addReadyQueue(conn redis.Conn, jobIDs []string, topic string) error {
	args := make([]interface{}, len(jobIDs)+1)
	args[0] = PREFIX_READY_QUEUE + topic
	for k, v := range jobIDs {
		args[k+1] = v
	}
	return conn.Send("LPUSH", args...)
}
